Overview
Initialization occurs after the infrastructure has been created, integrated and connected but before active objects are activated. This stage is provided to allow active objects and devices to initialize themselves before execution commences. Active objects also have specific initialization functions for their state and workspace. For information on entering initialization code refer to Entering Harness Code.
There is also a Prestart() call that occurs before circuit creation. This allows data required for circuit creation to be set up prior to circuit creation but asynchronously to the main GUI thread. For more information about the content of a circuit definition, refer to Circuit Definitions.
Examples
In the examples below the 'black' code is auto-generated by the translator, whilst the 'red' code is the additional user-provided code and 'green' highlights comments.
Initialise
Initialise() is used to initialize the object 'before' the object is run for the first time (on a each processor in the network). It is used to initialize state, workspace (default initialization is done in the base class) or to initialize any stores, semaphores that need to be set to their initial state.
The following example shows the Initialise() function for a thread. In this case the thread is initializing a single arbitrated store and an array of transient stores with appropriate values.
Uns Cct1_ControllerThrdElem::Initialise()
{
Uns failed = FALSE;
failed |= ! Cct1_ControllerThrdBaseElem::Initialise();
// initialize ControlData Ast to some
value
this->Aux1_ControlDataAst2Cxn().OpenWrite();
this->Aux1_ControlDataAst2Rec().Construct();
this->Aux1_ControlDataAst2Rec().Data().Value() = 1024;
this->Aux1_ControlDataAst2Cxn().Close();
// initialize all Grid Tsts to some
value
Uns i = 0;
for (Uns i = 0; i < NM; i++)
{
this->Aux3_GridTst2Cxn(i).OpenWrite();
this->Aux3_GridTst2Rec(i).Construct();
this->Aux3_GridTst2Rec(i).Initialise();
this->Aux3_GridTst2Rec(i).Data().Value()
= i;
this->Aux3_GridTst2Cxn(i).Close();
}
return ! failed;
}
The following example shows the Initialise() function for a method. In this case the method is initializing its state and workspace:
Uns Cct1_FFTMthdElem::Initialise()
{
Uns failed = FALSE;
failed |= ! Cct1_FFTMthdBaseElem::Initialise();
// initialize State and
workspace to non-default values
this->State().Data().Elem() = this->ElemNum();
this->Workspace().Data().ScratchPad() = new
Float[FFT_LENGTH];
this->Workspace().Data().ScratchPadSize() =
FFT_LENGTH;
return ! failed;
}